import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:sleep/help_style.dart';
import 'package:sleep/provider/wave_deatil_provider/wave_provider.dart';
import 'package:sleep/single/analyze/fatigue_analyze.dart';
import 'package:sleep/single/wave_show_model.dart';

const _colors = [
  Color(0xff652639),
  Color(0xff1F463E),
  Color(0xff34548F),
  Color(0xff725F40),
];
const _icons = [
  Icons.score,
  Icons.timelapse,
  Icons.disabled_visible,
  Icons.incomplete_circle,
];

class FgDetail extends ConsumerWidget {
  const FgDetail({
    super.key,
  });
  Widget card(int index, String title, String value) {
    return Container(
      padding: const EdgeInsets.only(top: 16, bottom: 16),
      decoration: HelpStyle.decoration,
      child: Column(
        children: [
          Icon(
            _icons[index],
            color: _colors[index],
          ),
          SizedBox(height: HelpStyle.cellMargin),
          Text(
            value,
            style: HelpStyle.contextStyle,
          ),
          SizedBox(height: HelpStyle.cellMargin * 0.5),
          Text(
            title,
            style: HelpStyle.smallStyle,
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context, ref) {
    final fatigue = ref.watch(fatigueProvider);
    final analyze = fatigue.analyze as FatigueAnalyze;
    FtaigueShowData? whole = analyze.showModel;
    return Row(
      children: [
        Expanded(child: card(0, 'BF', whole?.bf.toStringAsFixed(0) ?? "-")),
        SizedBox(width: HelpStyle.cellMargin),
        Expanded(child: card(1, 'BD', whole?.bd.toStringAsFixed(2) ?? "-")),
        SizedBox(width: HelpStyle.cellMargin),
        Expanded(child: card(2, 'CT', whole?.ct.toStringAsFixed(2) ?? "-")),
        SizedBox(width: HelpStyle.cellMargin),
        Expanded(
            child:
                card(3, 'PERCLOS', whole?.perclose.toStringAsFixed(0) ?? "-")),
      ],
    );
  }
}
